import jxl.*
import jxl.write.*

/**
 *
 * @author Tony Shen
 */
class ExcelUtils {
	static def writeExcel(out, map, objects) {
     // create our workbook and sheet
     def workbook = Workbook.createWorkbook(out)
     def sheet = workbook.createSheet("Requests", 0)

     // walk through our map and write out the headers
     def c = 0
     map.each() { k, v ->
         // write out our header
         sheet.addCell(new Label(c, 0, v.toString()))

         // write out the value for each object
         def r = 1
         objects.each() { o ->
             if (o[k]) {
                 if (o[k] instanceof java.lang.Number) {
                     sheet.addCell(new Number(c, r, o[k]))
                 } else {
                     sheet.addCell(new Label(c, r, o[k].toString()))
                 }
             }
             r++
         }
         c++
     }

     // close
     workbook.write()
     workbook.close()
 }
}

